package sendMail;

import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.MimeMessage;

public class CreateMail {
	public void send(String email,String pass){
		 Properties props = new Properties();
		 props.put("mail.smtp.auth", "true");
			props.put("mail.smtp.starttls.enable", "true");
			props.put("mail.smtp.host", "smtp.gmail.com");
			props.put("mail.smtp.port", "587");
	 
		    props.put("mail.from", "gaurav12291@gmail.com");
		    Session session = Session.getInstance(props, new GMailAuthenticator("gaurav12291","gasolinagasolina"));
		    try {
		        MimeMessage msg = new MimeMessage(session);
		        msg.setFrom();
		        msg.setRecipients(Message.RecipientType.TO,
		                          email);
		        msg.setSubject("Your investworks account password !!!! ");
		        msg.setSentDate(new Date());
		        msg.setText("YOUR GENERATED PASSWORD IS     "+pass);
		        Transport.send(msg);
		    } catch (MessagingException mex) {
		        System.out.println("send failed, exception: " + mex);
		    }
	}
}
